package cn.ywang.pattern.singleton.hungry;

/**
 * 饿汉式单例
 *
 * @author BeatificWang
 * @date 2019/3/10 14:29
 */
public class Hungry {

	private static final Hungry INSTANCE = new Hungry();

	/**
	 * 防止反射重复创建，破坏单例
	 */
	private Hungry() {
		if (null != INSTANCE) {
			throw new RuntimeException("不允许重复创建单例");
		}
	}

	public static Hungry getInstance() {
		return INSTANCE;
	}

	/**
	 * 防止反序列化破坏单例
	 *
	 * @return
	 */
	public Hungry readResolve() {
		return INSTANCE;
	}
}
